package com.bd.rj.frontstage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bd.rj.common.entity.Collections;
import com.bd.rj.common.entity.Post;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;
import java.util.Map;


/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 白世俊
 * @since 2025-01-03
 */
@Mapper
public interface CollectionsMapper extends BaseMapper<Collections> {

    /**
     * @desc 根据收藏表collections表和post表关联查询
     * @param uid
     * @return
     */
    @Select("SELECT p.type,p.address,p.salary,p.postname, c.* FROM post p INNER JOIN collections c ON p.id = c.pid WHERE c.uid = #{uid}")
    List<Map<String, Object>> selectByUidAndType(@Param("uid") Long uid);

    /**
     * 批量删除
     *
     * @author WBW
     * @param idList
     */
    @Delete({
            "<script>",
            "DELETE FROM collections WHERE id IN",
            "<foreach item='id' index='index' collection='idList' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    void batchDeleteByIds(@Param("idList") List<Long> idList);
}
